let isReallyNull = obj => {
  let isReallyNull = false;
  if (typeof obj === "undefined") {
    isReallyNull = true;
  }
  if (typeof obj === "string") {
    if (obj.trim().length === 0) {
      isReallyNull = true;
    }
  }
  if (typeof obj === "object") {
    if (obj === null) {
      isReallyNull = true;
    } else {
      isReallyNull = Object.keys(obj).length === 0;
    }
  }
  return isReallyNull;
};
var getProductPrice = function(obj) {
  if (!isReallyNull(obj) && JSON.parse(obj) !== 0) {
    obj = "￥" + obj;
  } else {
    if (obj === "" || JSON.parse(obj) === null || JSON.parse(obj) === 0) {
      obj = "";
    }
  }
  return obj;
};
let joinstr = function(spstr = " ", ...argms) {
  var str = "";
  for (let key in argms) {
    if (argms.hasOwnProperty(key)) {
      let element = argms[key];
      if (!isReallyNull(element)) {
        str += element + spstr;
      }
    }
  }
  str = str.substr(0, str.length - 1);
  return str;
};

let getgalleryImg = function(obj, size) {
  if (!isReallyNull(obj)) {
    var postion = obj.lastIndexOf("/");
    obj =
      obj.substring(0, postion + 1) + size + obj.substring(postion, obj.length);
  } else {
    return "/static/imgs/bondlogo.png";
  }
  return obj;
};
let getVideoFirstPicture = function(obj) {
  var fp = "";
  fp = obj.substring(0, obj.lastIndexOf(".") + 1) + "jpg";
  return fp;
};
function getReallyLength(str) {
  var length = 0;
  if (typeof str === "string") {
    var tempstr = str.replace(/([\u4e00-\u9fa5])/g, "aa");
    length = tempstr.length;
  }
  return length;
}
let subStr = function(str, num, endstr = "") {
  var tempstr = null;
  if (typeof str === "string") {
    var strlength = getReallyLength(str);
    if (typeof num === "number") {
      if (strlength <= num) {
        tempstr = str;
      } else {
        var reg = /[\u4e00-\u9fa5]/;
        var tempnum = 0;
        tempstr = "";
        for (const s of str) {
          ++tempnum;
          if (reg.test(s)) {
            ++tempnum;
          }
          if (tempnum <= num) {
            tempstr += s;
          }
        }
        tempstr = tempstr + endstr;
      }
    }
  }
  return tempstr;
};

export default {
  getgalleryImg,
  subStr,
  joinstr,
  getProductPrice,
  getVideoFirstPicture
};
